package cn.wolfcode.wolf2w.business.listener;

import cn.wolfcode.wolf2w.business.api.domain.Note;
import cn.wolfcode.wolf2w.business.api.domain.NoteEs;
import cn.wolfcode.wolf2w.business.api.domain.Strategy;
import cn.wolfcode.wolf2w.business.api.domain.StrategyEs;
import cn.wolfcode.wolf2w.business.repository.NoteEsRepository;
import com.alibaba.fastjson2.JSON;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class NoteRabbitListener {
    @Autowired
    private NoteEsRepository noteEsRepository;

    @RabbitListener(queues = "noteQueue")
    public void onMessage(String message){
        Note note = JSON.parseObject(message, Note.class);
        NoteEs es=new NoteEs();
        BeanUtils.copyProperties(note,es);

        noteEsRepository.save(es);
    }
}
